<?php

class nearbyyouhui
{
public function index()
{
$root = array();
$root['return'] = 1;
$city_id = intval($GLOBALS['request']['city_id']);
$ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
$ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
$xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
$xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
$m_distance = doubleval($GLOBALS['request']['m_distance']);
$ypoint =  $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
$xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
$page = intval($GLOBALS['request']['page']);
$page=$page==0?1:$page;
$page_size = PAGE_SIZE;
$limit = (($page-1)*$page_size).','.$page_size;
$pi = 3.14159265;
$r = 6378137;
$now = get_gmtime();
$sql_count = 'select count(*) from '.DB_PREFIX.'youhui ';
$sql = "select id, supplier_id as merchant_id,name as title,list_brief as content,icon as merchant_logo,create_time,xpoint,ypoint,address as api_address,icon as image_1,
				(ACOS(SIN(($ypoint * $pi) / 180 ) *SIN((ypoint * $pi) / 180 ) +COS(($ypoint * $pi) / 180 ) * COS((ypoint * $pi) / 180 ) *COS(($xpoint * $pi) / 180 - (xpoint * $pi) / 180 ) ) * $r) as distance  
				from ".DB_PREFIX.'youhui';
$where = " ypoint > $ybottom and ypoint < $ytop and xpoint > $xleft and xpoint < $xright and is_effect = 1 and begin_time<".$now.' and (end_time = 0 or end_time > '.$now.') ';
$sql.= ' where '.$where;
$sql.=' order by distance asc ';
$sql_count.=' where '.$where;
$sql.=' limit '.$limit;
$total = $GLOBALS['db']->getOne($sql_count);
$page_total = ceil($total/$page_size);
$list = $GLOBALS['db']->getAll($sql);
$youhui_list = array();
foreach($list as $item){
$item = m_youhuiItem($item);
$item['distance'] = round($item['distance']);
$youhui_list[] = $item;
}
$root['item'] = $youhui_list;
$root['page'] = array('page'=>$page,'page_total'=>$page_total);
output($root);
}
}

?>